import store from '../../store'
import { getStore } from '@/utils/util'

import { _get, _post, _all } from '../http'

export default {
  login: async (data) => {
    let setting = {
      url: 'login',
      params: data,
      header: {
        'Content-Type': 'multipart/form-data'
      }
    }

    return await _post(setting)
  },

  // 验证码
  async getCode(data) {
    return await _post({
      url: 'loginCode',
      params: data || {}
    })
  },

  // 超管登录
  async superAdminLogin(data) {
    return await _post({
      url: 'adminLogin',
      params: data || {}
    })
  },

  getUserInfo: () => {
    let roles = [
      '01000000',
      '02000000',
      '03000000',
      '04000000',

      '01010000',
      '01010001',

      '01020000',
      '01020001',

      '01030000',
      '01030001',

      '02010000',
      '02010001',

      '03010000',
      '03010001',

      '03020000',
      '03020001',

      '03030000',
      '03030001',

      '03040000',
      '03040001',

      '03050000',
      '03050001',

      '03060000',
      '03060001'
    ]

    // let rolesArr = getStore('rolesArr')
    // if (rolesArr && rolesArr.length) {
    //   roles = rolesArr
    // }

    let res = {
      name: getStore('userInfo') ? getStore('userInfo').username : '',
      roles
    }
    store.commit('setRoles', res.roles)
    store.commit('setInfo', res)

    return res
  }
}
